package com.bsoft.exchange.service;


import java.util.List;

import com.bsoft.exchange.dao.portal.HospitalInformationMapper;
import com.bsoft.exchange.domain.BridFymx;
import com.bsoft.exchange.domain.HospitalInformation;
import com.bsoft.exchange.util.CacheSupport;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsoft.exchange.dao.his.ListAppointmentWaitMapper;
import com.bsoft.exchange.domain.ListAppointmentWait;
import com.bsoft.exchange.pojo.ListAppointmentWaitPojo;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;


@Service
public class ListAppointmentWaitService {

	private static final Logger logger = LoggerFactory.getLogger(ListAppointmentWaitService.class);
	
	private List<String> brdaList;
	@Autowired
	ListAppointmentWaitMapper listAppointmentWaitmapper;
	@Autowired
	PublicService publicService;
	@Autowired
	CacheSupport cacheSupport;
	@Autowired
	HospitalInformationMapper hospitalInformationMapper;
	public BaseResponse<List<ListAppointmentWait>> selectList(ListAppointmentWaitPojo listAppointmentWaitPojo){
		BaseResponse<List<ListAppointmentWait>>baseResponse=new BaseResponse<>();
		//获取病人档案
		if (!listAppointmentWaitPojo.getQueryType().equals(1)){
            brdaList= publicService.getBRIDist(listAppointmentWaitPojo.getOrganizationId(),
					listAppointmentWaitPojo.getQueryType(),listAppointmentWaitPojo.getPatientIdentityCardList(),listAppointmentWaitPojo.getPatientMedicalCardNumberList());
        }else{
            brdaList = listAppointmentWaitPojo.getPatientIdList();
        }
		logger.info("===== brdaList:{} ======",brdaList);
        if (brdaList==null || (brdaList.size() > 0 && "".equals(brdaList.get(0))) || brdaList.size() == 0){
            baseResponse.setCode(Constant.errorTag);
            baseResponse.setMessage("病人查询失败");
            return baseResponse;
        }


		PageHelper.startPage(listAppointmentWaitPojo.getPageNo(), listAppointmentWaitPojo.getPageSize());
		List<ListAppointmentWait> listAppointmentWait = listAppointmentWaitmapper.selectList(listAppointmentWaitPojo.getOrganizationId(),
				listAppointmentWaitPojo.getVisitStatus(),
				listAppointmentWaitPojo.getOutpatientType(),
				listAppointmentWaitPojo.getPageNo() + 1,
				listAppointmentWaitPojo.getPageSize(),brdaList);
		List<HospitalInformation> hospitalInformationList=cacheSupport.getJgmcList(listAppointmentWaitPojo.getOrganizationId(), listAppointmentWaitPojo.getOrganizationId()+"jgmc",hospitalInformationMapper);
		for (ListAppointmentWait wait:listAppointmentWait){
			for (HospitalInformation jgxx:hospitalInformationList){
				if (wait.getOrganizationId().equals(jgxx.getOrganizationId())){
					wait.setOrganizationName(jgxx.getOrganizationName());
				}
			}
		}
		baseResponse.setCode(Constant.successResponse);
		baseResponse.setData(listAppointmentWait);
        return baseResponse;
		
	}
	

}